package thread.ch04;

import thread.annotation.GuardBy;
import thread.annotation.ThreadSafe;

@ThreadSafe
public final class Counter {

	@GuardBy("this")
	private long value = 0;
	
	public synchronized long getValue() {
		return value;
	}
	
	public synchronized long increment() {
		if (value == Long.MAX_VALUE) {
			throw new IllegalStateException("counter overflow");
		}
		return ++ value;
	}
}
